package com.crm.business.agreement.controller;

import com.crm.business.agreement.service.IBillAgreementSealSubjectService;
import com.crm.business.agreement.service.IBillAgreementTemplateService;
import com.crm.business.servlet.BaseMapper;
import com.crm.common.agreement.entity.BO.SealSubjectBO;
import com.crm.common.agreement.entity.BO.TemplateBo;
import com.crm.common.agreement.entity.PO.BillAgreementSealSubject;
import com.crm.common.agreement.entity.PO.BillAgreementTemplate;
import com.crm.common.ka.core.common.R;
import com.crm.common.ka.core.common.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/template")
@Api(tags = "协议模板接口")
public class BillAgreementTemplateController {

    @Autowired
    private IBillAgreementTemplateService billAgreementTemplateService;

    @PostMapping("/add")
    @ApiOperation("保存模板")
    public Result add(@RequestParam("fileId") Long fileId, @RequestBody TemplateBo model) throws IOException {
        String result = billAgreementTemplateService.save(fileId,model);
        Map<String,String> map = new HashMap<>();
        map.put("result",result);
        return R.ok(map);
    }

    @PostMapping("/queryPageList")
    @ApiOperation("模板分页数据")
    public Result queryPageList(@RequestBody TemplateBo model) {
        return R.ok(billAgreementTemplateService.queryPageList(model));
    }

    @PostMapping("/queryList")
    @ApiOperation("全量模板数据")
    public Result queryList(@RequestBody TemplateBo model) {
        return R.ok(billAgreementTemplateService.queryList(model));
    }


    @PostMapping("/update")
    @ApiOperation("更新模板")
    public Result update(@RequestParam("fileId") Long fileId, @RequestBody TemplateBo model) throws IOException {
        String result = billAgreementTemplateService.update(fileId,model);
        Map<String,String> map = new HashMap<>();
        map.put("result",result);
        return R.ok(map);
    }


    @GetMapping("/getTemplateInfo")
    @ApiOperation("模板详情")
    public Result getTemplateInfo(@RequestParam("templateId") Long templateId) throws IOException {
        Map<String,Object> map = billAgreementTemplateService.getTemplateInfo(templateId);
        return R.ok(map);
    }


    @GetMapping("/previewUrl")
    @ApiOperation("预览地址")
    public Result previewUrl(@RequestParam("templateId") Long templateId) throws IOException {
        Map<String,Object> map = billAgreementTemplateService.previewUrl(templateId);
        return R.ok(map);
    }

    @GetMapping("/upStatus")
    @ApiOperation("更新模板状态")
    public Result upStatus(@RequestParam("templateId") Long templateId, @RequestParam("status") Integer status) throws IOException {
        int i = billAgreementTemplateService.upStatus(templateId,status);
        return R.ok(i);
    }


    @GetMapping("/delTemplate")
    @ApiOperation("删除模板")
    public Result delTemplate(@RequestParam("templateId") Long templateId) throws IOException {
        int i = billAgreementTemplateService.delTemplate(templateId);
        return R.ok(i);
    }
}


